import math, time
import numpy as np
import sys

def timeSince(since):
    '计算时间长度'
    now = time.time()
    s = now - since
    m = math.floor(s / 60)
    s -= m * 60
    return '%d:%d' % (m, s)

def ifNotDecrease(loss_data, len=5, epoch=0):
    if epoch == 0: loss_list = np.array(loss_data) - loss_data[0]
    else: loss_list = np.array(loss_data[-len:-1]) - np.array(loss_data[-len * 2:-len - 1])
    if np.sum(loss_list) >= 0:
        return True
    return False

def basic_rule(epoch, lr):
    return lr

def filePrint(*values, file=sys.stdout, **kwargs):
    print(*values, **kwargs)
    print(*values, file=file, **kwargs)
